package com.sk.ccflower.server.lib.dbUtils.sql;

import java.util.ArrayList;

import com.sk.ccflower.lib.commonBeans.DefaultParamBean;
import com.sk.ccflower.lib.define.DBTable;
import com.sk.ccflower.server.lib.dbBeans.MfCommentBean;
import com.sk.ccflower.server.lib.dbUtils.SQLReturn;

public class MfCommentSql extends BaseSql {
	
	private static final String m_column = "src_user, dest_user, c_type, score, comment, c_date, confirm";
	private static final String m_column_insert = "src_user, dest_user, c_type, score, comment, confirm";
	
	private static final String m_basequery = "SELECT * FROM " + DBTable.MF_COMMENT;
	private static String m_insertQuery = null;
	
	static {
		m_insertQuery = makeInsertSql(DBTable.MF_COMMENT, m_column_insert);
	}
	
	public MfCommentSql() throws Exception {
		super( MfCommentBean.class, "comment_idx" );
	}
	
	@Override
	protected void clearOtherHash() {
		// TODO Auto-generated method stub
	}

	@Override
	protected void initKeyFields() throws Exception {
		// TODO Auto-generated method stub
	}

	@Override
	protected void putInOtherHash(Object data) throws Exception {
		// TODO Auto-generated method stub
	}
	
	public static SQLReturn getSql() {
        SQLReturn sret = new SQLReturn();
        
        sret.m_query = m_basequery;
        sret.m_params = new ArrayList<Object>();
        sret.m_class = MfCommentBean.class;
        sret.m_colMap = null;
        
        return sret;
    }
	
	public static SQLReturn getSql( String email ) {
        SQLReturn sret = new SQLReturn();
        
        sret.m_query = m_basequery + " WHERE src_user = ? OR dest_user = ? ORDER BY c_date";
        sret.m_params = new ArrayList<Object>();
        sret.m_class = MfCommentBean.class;
        sret.m_colMap = null;
        sret.m_params = new ArrayList<Object>();
        sret.m_params.add( email );
        sret.m_params.add( email );
        
        return sret;
    }
	
	public static SQLReturn getSql( String src_user, String dest_user ) {
        SQLReturn sret = new SQLReturn();
        
        sret.m_query = m_basequery + " WHERE (src_user=? AND dest_user=?) OR (src_user=? AND dest_user=?) ORDER BY c_date";
        sret.m_params = new ArrayList<Object>();
        sret.m_class = MfCommentBean.class;
        sret.m_colMap = null;
        sret.m_params = new ArrayList<Object>();
        sret.m_params.add( src_user );
        sret.m_params.add( dest_user );
        sret.m_params.add( dest_user );
        sret.m_params.add( src_user );
        
        return sret;
    }
	
	public static SQLReturn getSqlInsert( MfCommentBean _bean ) {
		SQLReturn ret = new SQLReturn();
		
		ret.m_query = m_insertQuery;
		ret.m_class = MfCommentBean.class;
		ret.m_colMap = null;
		ret.m_params = new ArrayList<Object>();
		ret.m_params.add(_bean.src_user);
		ret.m_params.add(_bean.dest_user);
		ret.m_params.add(_bean.c_type);
		ret.m_params.add(_bean.score);
		ret.m_params.add(_bean.comment);
		ret.m_params.add(_bean.c_date);
		ret.m_params.add(_bean.confirm);
		
		return ret;
	}
	
	public static SQLReturn getSqlUpdate( MfCommentBean bean ) {
		SQLReturn sret = new SQLReturn();
		
		sret.m_query = "UPDATE " + DBTable.MF_COMMENT + " SET confirm=1 WHERE comment_idx=?";
		sret.m_class = MfCommentBean.class;
        sret.m_colMap = null;
        sret.m_params = new ArrayList<Object>();
        sret.m_params.add( new Integer(bean.comment_idx) );
        
        return sret;
    }
	
	public static SQLReturn getSqlDelete( String src_user, String dest_user ) {
    	SQLReturn sret = new SQLReturn();
    	
        sret.m_query = "DELETE FROM " + DBTable.MF_COMMENT + " WHERE (src_user=? AND dest_user=?) OR (src_user=? AND dest_user=?)";
        sret.m_class = MfCommentBean.class;
        sret.m_colMap = null;
        sret.m_params = new ArrayList<Object>();
        sret.m_params.add( src_user );
        sret.m_params.add( dest_user );
        sret.m_params.add( dest_user );
        sret.m_params.add( src_user );
        
        return sret;
    }
	
	public static SQLReturn getSqlscoreInit( DefaultParamBean bean ) {
		SQLReturn sret = new SQLReturn();
		
		sret.m_query = "UPDATE " + DBTable.MF_COMMENT + " SET score=0 WHERE dest_user=? and c_type in(1,2,3)";
		sret.m_class = DefaultParamBean.class;
        sret.m_colMap = null;
        sret.m_params = new ArrayList<Object>();
        sret.m_params.add( new String(bean.src_user) );
        
        return sret;
    }
	
}
